﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace IllustratedCsharp7_ch21_return_void
{
    class Chapt21_3AsyncMethodEx3_Return_Void
    {
        static void _Main()
        {
            DoAsyncStuff.CalculateSumAsync(5, 6);
            //处理其他事情
            Console.WriteLine($"主线程id：{ Thread.CurrentThread.ManagedThreadId}");

            Thread.Sleep(200);
            Console.WriteLine("Program Exiting");
        }
    }

    static class DoAsyncStuff
    {
        //使用"调用并忘记"的异步方法
        public static async void CalculateSumAsync(int i1, int i2)
        {
            int value = await Task.Run(() => GetSum(i1, i2));
            Console.WriteLine("Value{0}:", value);
            Console.WriteLine($"异步方法中线程id：{ Thread.CurrentThread.ManagedThreadId}");
        }
        private static int GetSum(int i1, int i2) { return i1 + i2; }
    }
}
